define(['vue'],
  function (Vue) {
    function render() {
      new Vue({
        el: '#tmzk_test',
        data() {
          return {
            eidtColumns: [
              {
                title: '员工', field: 'person',
                // 校验
                required: true,
                // validate: ({ row, rowIndex, column, columnIndex }) => {
                //   // return false
                //   return {
                //     validate: false
                //   }
                // },
                cellRender: {
                  name: 'SelectPerson',
                  events: {
                    change: ({ row,rowIndex }, person) => {
                      if(!$.elValidate.validateTabledata(this.editData,rowIndex,'person.code',person?.code)){
                        $.msg.tips('人员不能重复')
                        row.person = null
                        return
                      }
                    }
                  }
                }
              },
              {
                defaultValue: 0,
                title: '下拉选项', field: 'select',
                cellRender: {
                  name: 'ElSelect',
                  // 是否可编辑
                  // visible: true,
                  visible: ({ row }) => {
                    // 可根据数据是否编辑
                    return true
                  },
                  // options: [],
                  options: ({ row }) => {
                    return [
                      { id: 0, evaluationItemName: '早餐' },
                      { id: 1, evaluationItemName: '午餐' }
                    ]
                  },
                  // 下拉配置
                  optionProps: {
                    label: 'evaluationItemName',
                    value: 'id'
                  },
                  // 事件
                  events: {
                    change: ({ row }, cellValue) => {
                      console.log(row)
                      console.log(cellValue)
                    }
                  },
                  // 属性
                  props: {

                  }
                }
              },
              {
                title: '最小值', field: 'minScoreRange',
                minWidth: 100,
              },
              {
                title: '最大值', field: 'maxScoreRange',
                minWidth: 100,
              },
              {
                title: '评价得分', field: 'score',
                cellRender: {
                  visible: true,
                  name: 'ElInputNumber',
                  props: {
                    controls: false
                  },
                  events: {
                    change: ({ row }, cellValue) => {
                      console.log(row)
                      console.log(cellValue)
                    }
                  }
                },
                width: 80,
              }
            ],
            editData: [
              {
                person: null,
                select: 0, minScoreRange: 0, maxScoreRange: 300, score: ''
              }
            ]
          }
        },
        methods: {
          search(){
            console.log(this.editData)
          },
          addRow() {
            const row = $.Utils.getEmptyRow(this.eidtColumns)
            console.log(row)
            this.editData.push(row)
          },
          validate(){
            const validate = $.elValidate.validateTable(this.editData,this.eidtColumns)
            console.log(validate)
          }
        }
      })
    }
    return {
      init: render
    }
  })